﻿namespace MicroCloud.Entity.Database
{
    /// <summary>
    /// 实体信息实体映射配置
    /// </summary>
    public class EntityInfoConfiguration : EntityTypeConfigurationBase<EntityInfo, long>
    {
        /// <summary>
        /// 重写以实现实体类型各个属性的数据库配置
        /// </summary>
        /// <param name="builder">实体类型创建器</param>
        public override void Configuration(EntityTypeBuilder<EntityInfo> builder)
        {
            builder.HasIndex(m => m.Name).SetIndex("Name", false);
            switch (DbContextOptions?.DatabaseType)
            {
                case DatabaseType.SqlServer:
                case DatabaseType.PostgreSql:
                case DatabaseType.Oracle:
                    builder.HasIndex(m => m.TypeName).SetIndex("TypeName", true);
                    builder.HasIndex(m => new { m.DbSchema, m.DbObjName }).SetIndex("SchemaMapping");
                    builder.HasIndex(m => m.AuditEnabled).SetIndex("AuditEnabled");
                    builder.HasIndex(m => m.EventEnabled).SetIndex("EventEnabled");
                    break;
            }

            ConfigurationAppend(builder);
        }

    }
}